<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<style>
  .table {
    border: 1px solid #eee;
    border-collapse: collapse;
    text-align: center;

  }

  .table th,
  td {
    border: 1px solid #eee;
    padding: 10px 16px;
  }

  .table th {
    background-color: #ccc;
  }

  .count {
    margin: 0 5px
  }
</style>

<body>

  <div id="app">




  </div>
  <!-- 引入React依赖 -->
  <script src="../React/react.development.js"></script>
  <script src="../React/react-dom.development.js"></script>
  <script src="../React/babel.min.js"></script>
  <script src="./format-utils.js"></script>

  <!-- 编写React代码 -->
  <script type="text/babel">
    class App extends React.Component {
      constructor() {
        super()
        //定义变量
        this.state = {
          books: [
            {
              id: 1,
              name: '《算法导论》',
              date: ' 2006-9 ',
              price: 85.00,
              count: 1
            },
            {
              id: 2,
              name: '《UNIX编程艺 术》',
              date: ' 2006-2',
              price: 59.00,
              count: 1
            },
            {
              id: 3,
              name: '《编程珠玑》',
              date: ' 2008 -10',
              price: 39.00,
              count: 1
            }
          ],
        }
      }
      render() {
        const { books } = this.state

        return (
          <div>
            <table class="table">
              <thead>
                <tr>
                  <td></td>
                  <th>书籍名称</th>
                  <th>出版日期</th>
                  <th>价格</th>
                  <th>购买数量</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
                {
                  books.map((item, index) => {
                    return (
                      <tr>
                        <td>{index + 1}</td>
                        <td>{item.name}</td>
                        <td>{item.date}</td>
                        <td>{formatPrice(item.price)}</td>
                        <td>
                          <button>-</button>
                          <span className="count">{item.count}</span>
                          <button>+</button>
                        </td>

                        <td><button>移除</button></td>
                      </tr>
                    )
                  })
                }
                <td></td>
              </tbody>
            </table>
          </div>
        )
      }
    }
  </script>

  <script type="text/babel">
    ReactDOM.render(<App />, document.getElementById("app"))

  </script>

</body>

</html>